import java.util.Random;
import java.util.Scanner;

public class test {
    /*  public static void main(String[] args) {
          int a=0;
          int b=10;
          if(!(a>b)){
              System.out.printf("sss");   }
          System.out.printf("!a");
          System.out.printf("!true");
          System.out.printf("!false");
          System.out.printf("a==b");
          System.out.printf("a!=b");
          System.out.printf("a<b");
          System.out.printf("a<=b");
          System.out.printf("a>=b");


      }*/
    public static void main1(String[] args) {

   /*   int a=10;
      int b=a++;
      System.out.println(a);
      System.out.println(b);


      a+=b;
      a=(int)(a+b);
      System.out.println(a);
*/
     /* System.out.println(5/2);
      System.out.println((float)5/2);
      System.out.println(5/(float)2);
      System.out.println((float)(5/2));
      System.out.println(10%3);
      System.out.println(-10%3);
      System.out.println(10%-3);
      System.out.println(-10%-3);
*/
   /*   String str ="hello";
      System.out.println(str);
      System.out.println(str.length());*/
      /*String str2 ="345";
      int val=Integer.parseInt(str2);
      System.out.println(val+1);
      int p=100;
      String str3=String.valueOf(p);
      System.out.println(str3);
      int a=10;
      int b=20;
      System.out.println("a="+a+"b="+b);
      System.out.println("a+b="+a+b);
      System.out.println(a+b+"a+b");
      */
/*
      int a=10;
      int b=20;
      long c=a+b;
      int c2=(int)(a+b);
      byte f=10;
      byte f2=20;
      int f3=f+f2;
      byte f4=(byte)(f+f2);
      System.out.println(c);
      System.out.println(f);
      System.out.println(f2);
      System.out.println(f3);
*/
/*
       char a='a';
       char b='关';
      System.out.println(a);
      System.out.println(b);
      boolean flg=true;
      System.out.println(flg);
      */
/*double d=12.4;
      System.out.println(d);
      double a=1.0;
      double b=2.0;
      System.out.println(a/b);
      int c=1;
      int e=2;
      System.out.println(c*1.0/e);
      double num=1.1;
      System.out.println(num*num);
      float f=12.5f;
      System.out.println(f);*/
   /*   short a=10;
      System.out.println(a);
      System.out.println(Short.MAX_VALUE);
      System.out.println(Short.MIN_VALUE);
      byte b=127;
      System.out.println(Byte.MIN_VALUE);
      System.out.println(Byte.MAX_VALUE);
      */
/*      long a=10L;
      System.out.println(a);
      System.out.println(Long.MAX_VALUE);
      System.out.println(Long.MIN_VALUE);*/
 /*         int a=10;
      int c = 8921779+a;
      System.out.println(c);
      System.out.println(Integer.MIN_VALUE);
      System.out.println(Integer.MAX_VALUE);*/


    }

    public static void main2(String[] args) {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 10 == 9 || i / 10 == 9) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main3(String[] args) {
        for (int i = 1000; i <= 2000; i++) {
            if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) {
                System.out.println(i + "是闰年");
            }
        }
    }

    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i;
        for (i = 2; i < n; i++) {
            if (n % i == 0) {
                System.out.println("n不是素数" + n);
                break;
            }
        }
        if (i >= n) {
            System.out.println("是素数" + n);
        }
    }

    public static void main23(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int age = scanner.nextInt();
        if (age < 18) {
            System.out.println("少年");
        } else if (age > 18 && age <= 28) {
            System.out.println("青年");
        } else if (age >= 29 && age <= 55) {
            System.out.println("中年");
        } else {
            System.out.println("老年");

        }
    }

    public static void main99(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (i == j) {
                        System.out.print("*");
                    } else if (i + j + 1 == n) {
                        System.out.print("*");
                    } else {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }


        }
    }

    public static void main43(String[] args) {
        Random random = new Random();
        Scanner sc = new Scanner(System.in);
        int toGuess = random.nextInt(100);

        while (true) {
            System.out.println("请输入你想猜的数字");
            int num = sc.nextInt();
            if (num < toGuess) {
                System.out.println("低了");
            } else if (num > toGuess) {
                System.out.println("高了");

            }
            else {
                System.out.println("猜对了");
                break;
            }

        }
    }

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n= scanner.nextInt();
        for (int i = 0; i <n; i++) {
            int count=1;
            int tmp=i;
            int sum=0;
            while (tmp/10!=0){
                count++;
                tmp=tmp/10;

        }
               tmp =i;
            while (tmp!=0){
                sum+=Math.pow(tmp%10,count);
                tmp=tmp/10;

            }
            if(sum==i)
            {
                System.out.println(i);
            }
        }
    }
}
